// pages/parentKaoqinInfor/parentKaoqinInfor.js
var api = require('../../utils/api.js');
var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    attendanceList:[],
    date1: '',
    date2: '',
  },


//获取考勤信息
getKaoqinList(page){
  api.fetchApi('student/attendance', { token: wx.getStorageSync('token'), page, start_time: this.data.date1, end_time: this.data.date2}).then(res => {
    var attendanceList = this.data.attendanceList;
    var attendanceList1 = res.data;
    console.log(res)
    if (attendanceList1.length == 0 && page > 1) {
      //api.showToast('到底啦!', 'http://qnwmfx.laigl.com/iconimg/warn.png', 1500)
      this.setData({
        isMore: true
      })
      return
    }
    attendanceList = [...attendanceList, ...attendanceList1];
    var att_info = res.att_info;
    this.setData({
      attendanceList,
      page,
      att_info
    })

  })
},

  //时间始
  dateChange1(e) {

   
    this.setData({
      date1: e.detail.value,
      attendanceList: []
    })

    this.getKaoqinList(1)
  },

  //时间止
  dateChange2(e) {
    this.setData({
      date2: e.detail.value,
      attendanceList:[]
    })
    this.getKaoqinList(1)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getKaoqinList(1);
    var date1 = new Date().dateFormat('Y-m-d');
    var date2 = (new Date(new Date().valueOf() + 86400000)).dateFormat('Y-m-d')
    console.log(date1, date2)
    this.setData({
      date1,
      date2
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var page = this.data.page || 1;
    page++;
    
    this.getKaoqinList(page)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})